package com.ruoyi.manager.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.manager.to.SoldierBaseInfoTo;
import com.ruoyi.manager.to.SoldierFullMessageDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manager.domain.SoldierBaseInfo;
import com.ruoyi.manager.service.ISoldierBaseInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 基本信息Controller
 *
 * @author Allen
 * @date 2021-08-30
 */
@RestController
@RequestMapping("/manager/retirefm")
public class SoldierBaseInfoController extends BaseController {
    @Autowired
    private ISoldierBaseInfoService soldierBaseInfoService;

    /**
     * 查询基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('manager:retirefm:list')")
    @GetMapping("/list")
    public TableDataInfo list(SoldierBaseInfo soldierBaseInfo) {
        startPage();
        List<SoldierBaseInfo> list = soldierBaseInfoService.selectSoldierBaseInfoList(soldierBaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('manager:retirefm:export')")
    @Log(title = "基本信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SoldierBaseInfo soldierBaseInfo) {
        List<SoldierBaseInfo> list = soldierBaseInfoService.selectSoldierBaseInfoList(soldierBaseInfo);
        ExcelUtil<SoldierBaseInfo> util = new ExcelUtil<SoldierBaseInfo>(SoldierBaseInfo.class);
        return util.exportExcel(list, "基本信息数据");
    }

    /**
     * 获取基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:retirefm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(soldierBaseInfoService.selectSoldierBaseInfoById(id));
    }

    /**
     * 新增基本信息
     */
    @PreAuthorize("@ss.hasPermi('manager:retirefm:add')")
    @Log(title = "基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SoldierBaseInfo soldierBaseInfo) {
        return toAjax(soldierBaseInfoService.insertSoldierBaseInfo(soldierBaseInfo));
    }

    /**
     * 修改基本信息
     */
    @PreAuthorize("@ss.hasPermi('manager:retirefm:edit')")
    @Log(title = "基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SoldierBaseInfo soldierBaseInfo) {
        return toAjax(soldierBaseInfoService.updateSoldierBaseInfo(soldierBaseInfo));
    }

    /**
     * 删除基本信息
     */
    @PreAuthorize("@ss.hasPermi('manager:retirefm:remove')")
    @Log(title = "基本信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(soldierBaseInfoService.deleteSoldierBaseInfoByIds(ids));
    }

    @GetMapping("/getSoldierFullMessage")
    public AjaxResult getSoldierFullMessage(String idNumber) {
        return AjaxResult.success(soldierBaseInfoService.getSoldierFullMessage(idNumber));
    }

    @PostMapping("addSoldierFullMessage")
    public AjaxResult addSoldierFullMessage(SoldierFullMessageDto soldierFullMessageDto) {
        return toAjax(soldierBaseInfoService.addSoldierFullMessage(soldierFullMessageDto));
    }

    @Log(title = "基本信息", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('manager:retirefm:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<SoldierBaseInfoTo> util = new ExcelUtil<SoldierBaseInfoTo>(SoldierBaseInfoTo.class);
        List<SoldierBaseInfoTo> userList = util.importExcel(file.getInputStream());

        soldierBaseInfoService.importBaseInfo(userList);
        return AjaxResult.success(null);
    }
}
